//
//  driveSchoolCell.m
//  jiaKaoZhuShou
//
//  Created by 金艺社 on 2018/5/15.
//  Copyright © 2018年 金艺社. All rights reserved.
//

#import "driveSchoolCell.h"

@implementation driveSchoolCell

- (void)awakeFromNib {
    [super awakeFromNib];
    // Initialization code
    if ([self respondsToSelector:@selector(setSeparatorInset:)]) {
        [self setSeparatorInset:UIEdgeInsetsMake(0, 0, 0, 0)];
    }
    if ([self respondsToSelector:@selector(setPreservesSuperviewLayoutMargins:)]) {
        [self setPreservesSuperviewLayoutMargins:NO];
    }
    if ([self respondsToSelector:@selector(setLayoutMargins:)]) {
        [self setLayoutMargins:UIEdgeInsetsZero];
    }
    self.priture_img.contentMode = UIViewContentModeScaleAspectFit;
    self.priture_img.backgroundColor = [UIColor gk_colorWithHexString:@"#f2f2f2"];
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

    // Configure the view for the selected state
}

- (void)setModel:(driveSchoolModel *)model {
    _model = model;
    self.name_lab.text = _model.companyName;
    self.price_lab.text = [NSString stringWithFormat:@"%@元", _model.money];
    [self.priture_img sd_setImageWithURL:[NSURL URLWithString:model.img] placeholderImage:[UIImage imageNamed:@"photo"]];
    self.distance_lab.text = [NSString stringWithFormat:@"距离%.2f千米", _model.distance.floatValue];
    [self start:[NSNumber numberWithDouble:_model.start.doubleValue]];
    self.number_lab.text = [NSString stringWithFormat:@"%@人评价", _model.commentCount];
}
- (void)start:(NSNumber *)number {
    float a = number.floatValue;
    int b = floor(a);//整个星
    float c = a - b;//半个星
    UIView *subView = [self.contentView subviews].firstObject;
    NSArray *subViews = subView.subviews;
    for (UIView *V in subViews) {
        if ([V isKindOfClass:[UIImageView class]] && V.tag == 100) {
            UIImageView *imgView = (UIImageView *)V;
            imgView.image = [UIImage imageNamed:@"greaStars"];
            if (b > 0) {
                imgView.image = [UIImage imageNamed:@"yellowStars"];
                b--;
            }else if (c > 0) {
                imgView.image = [UIImage imageNamed:@"halfStars"];
                c = 0.0;
            }
        }
    }
}
@end
